<%@page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="com.meconsea.im.bean.*" %>

<%

	String enterpriseId = (String)request.getAttribute("enterpriseId");
	Map allUser = (Map)request.getAttribute("allUser");
	if(allUser == null){
		allUser = new HashMap();
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%
	String contextPath = request.getContextPath();
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>企业管理</title>
<link href="<%=contextPath%>/css/friend.css" rel="stylesheet" type="text/css"/>
<link href="<%=contextPath%>/css/css1.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=contextPath%>/js/checkUtil.js"></script>
<script src="<%=contextPath%>/im/js/prototype.js" type="text/javascript"></script>
<script src="<%=contextPath%>/im/js/xhconn.js" type="text/javascript"></script>
<script src="<%=contextPath%>/im/js/json.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript"> 
  function modify(imu_id){
  	 $("username").value = $(imu_id+"un").innerHTML;
  	 $("username").readonly = 'true';
  	 $("nickname").value = $(imu_id+"nn").innerHTML;
  	 $("userIntro").value = $(imu_id+"ui").innerHTML;
  	 $("ImUForm").action = "<%=contextPath%>/imEnterpriseService.do?action=update";
  	 $("ImUFormTab").style.display='';
  }
  function subIMUser(){
  	 var _act = $("ImUForm").action;
  	 if($("username").value.realLength < 4){
  	 	 alert("登录名不能为空.");
  	 	 return false;
  	 }
  	 if($("nickname").value.realLength < 1){
  	 	 alert("昵称不能为空.");
  	 	 return false;
  	 }
  	 if($("userIntro").value.realLength < 4){
  	 	 alert("简介不能为空.");
  	 	 return false;
  	 }
  	 $("addBtn").onclick= function(){};
  	 if(_act.indexOf("add") != -1){
  	 	var pingTo = "<%=contextPath%>/imEnterpriseService.do";
  	 	var xhConn = new XHConn();
  	 	xhConn.connect(pingTo,"POST","call=reg&action=validate&username="+$("username").value,
  	 		function(xh){
  	 			if(xh.responseText.realLength < 1){
 					alert("用户名校验错误，请与站长联系。");
 					$("addBtn").onclick= function(){subIMUser();return false};
 					return false;
	 			}else{
	 				var responseJ = xh.responseText.parseJSON();
	 				var uinfo = responseJ.userinfo;
	 				var validate = uinfo.validate;
	 				if(validate == "0"){
	 					alert("系统找不到"+$("username").value+"用户.");
 					$("addBtn").onclick= function(){subIMUser();return false};
	 					return false;
	 				}else if(validate == "2"){
	 					var en = uinfo.enterpriseName;
	 					alert($("username").value+"已加入"+en+".");
 					$("addBtn").onclick= function(){subIMUser();return false};
	 					return false;
	 				}else if(validate == "1"){
	 					var un = uinfo.username;
	 					var nn = uinfo.nickname;
	 					var rn = uinfo.realname;
	 					var info_ = "将会员"+un+"加入您的企业中吗？该会员的在系统的昵称为："+nn+",真实姓名："+rn;
	 					if(confirm(info_)){ 
  	 						$("ImUForm").submit();
	 					}else{ 
 							$("addBtn").onclick= function(){subIMUser();return false};
	 					}
	 				}
	 			}
  	 		});
  	 }else{
  	 	$("ImUForm").submit();
  	 }
  }
  function addImU(){
  	$("username").value = "";
  	$("username").readonly = 'false';
  	$("nickname").value = "";
  	$("userIntro").value = "";
  	$("ImUForm").action = "<%=contextPath%>/imEnterpriseService.do?action=add";
  	$("ImUFormTab").style.display='';
  }
  
  function deleteIM(uname){
  	 if(confirm("确实要删除"+uname+"吗？")){
  	 	window.location.href="<%=contextPath%>/imEnterpriseService.do?action=delete&username="+uname+"&enterpriseId=<%=enterpriseId%>";
  	 }
  }
</script>
</head>
<body>
<div id="f_bg">
  <div id="f_tabs">
    <ul>
      <li id="tab1" class="f_tabClass1"><a href="<%=contextPath%>/imEnterpriseService.do?action=getImEn&enterpriseId=<%=enterpriseId %>" >企业信息</a></li>
      <li id="tab2" class="f_tabClass2">专家信息</li>
    </ul>
  </div>
</div>
<div id="f_main">
  <div id="friendlist">  </div>
  <div id="addfriend">
  <table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
  	<td align='center'><span class="font1"><strong> </strong>&nbsp;&nbsp;&nbsp;&nbsp;等级： </span></td>
  </tr>
  <tr>
    <td><hr size="3" noshade style="color:#FCD4D2"></td>
  </tr>
</table>
<table width="750" border="0" align="center" cellpadding="8" cellspacing="0">
  <tr>
  	<td>登录名</td>
  	<td>昵称</td>
  	<td>简介</td>
  	<td>是否在线</td>
  	<td>等级</td>
  	<td>登录次数</td>
  	<td>操作</td>
  </tr>
  <% 
  	 Iterator it = allUser.entrySet().iterator();
  	 while(it.hasNext()){
  	 	Map.Entry me = (Map.Entry)it.next();
  	 	String uId = (String)me.getKey();
  	 	IMUser imu_t = (IMUser)me.getValue();
  	 	int online = imu_t.getOnline();
  	 	String olStr = "";
  	 	if(online == 0 || online == 50){
  	 		olStr = "离线";
  	 	}else if(online == 2){
  	 		olStr = "离开";
  	 	}else{
  	 		olStr = "在线";
  	 	}
  	 	double creditLevel = imu_t.getCreditlevel();
  	 	String clImg = "";
  	 	for(int i = 1; i < creditLevel; i++){
  	 		clImg += "<img src='"+contextPath+"/im/images/xx.ico' width=12px height=12px'/>";
  	 	}
  	 	
  %>
  <tr>
  	<td id="<%=uId+"un" %>"><%=imu_t.getUsername() %></td>
  	<td id="<%=uId+"nn" %>"><%=imu_t.getNickname() %></td>
  	<td id="<%=uId+"ui" %>"><%=imu_t.getUserintro() %></td>
  	<td id="<%=uId+"uo" %>"><%=olStr %></td>
  	<td id="<%=uId+"cl" %>"><%=clImg %></td>
  	<td id="<%=uId+"ln" %>"><%=imu_t.getLoginsum() %></td>
  	<td><a href="javascript:modify('<%=uId %>')">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:deleteIM('<%=imu_t.getUsername() %>')">删除</a></td>
  </tr>
  <%
  	 }
  %>
  <tr>
  	<td colspan="7" align="right"><input type="button" style="button1" name="addBtn" value="添加" onclick="addImU()"></td>
  </tr>
</table>
<form action="<%=contextPath%>/imEnterpriseService.do" method="POST" name="ImUForm">
<table id="ImUFormTab" width="750" border="0" align="center" cellpadding="8" cellspacing="0" style="display:none">
  <tr>
  	<td>会员登录名：</td>
  	<td id="imu_un"><input type="text" name="username"></td>
  </tr>
  <tr>
  	<td>会员昵称：</td>
  	<td><input type="text" name="nickname"></td>
  </tr>
  <tr>
  	<td>会员简介：</td>
  	<td><textarea  name="userIntro"></textarea></td>
  </tr>
  <tr>
  	<td><input type="hidden" name="enterpriseId" value="<%=enterpriseId %>"></td>
  	<td></td>
  </tr>
  <tr>
  	<td></td>
  	<td><input type="button" style="button1" name="addBtn" value="保存" onclick="subIMUser()"></td>
  </tr>
</table>
  </div>
</div>
</body>
</html>